package com.jade.yh.zsy.mobile.store.api;

import com.jade.bss.base.RoleAction;
import com.jade.bss.base.utils.CopyBean;
import com.jade.bss.web.resolver.CustomerCapsule;
import com.jade.framework.base.context.ApplicationContextUtils;
import com.jade.framework.base.util.PagingResult;
import com.jade.framework.base.util.ResponseUtils;
import com.jade.zsy.base.common.ParametersException;
import com.jade.zsy.base.entity.Store;
import com.jade.zsy.base.facade.StoreFacade;
import com.jade.zsy.base.vo.StoreVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.MediaType;
import org.springframework.validation.Errors;
import org.springframework.validation.FieldError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * Created with IntelliJ IDEA.
 * User: jinya
 * Date: 2017/6/5
 * Time: 15:17
 * TEL :17701640710   MAIL:2009_jinya@163.com
 * To change this template use File | Settings | File Templates.
 */
@RestController
@RequestMapping(value = "/store", produces = MediaType.APPLICATION_JSON_VALUE)
@Api(value = "店铺管理", description = "店铺管理")
public class StoreApi {
    private StoreFacade storeFacade = ApplicationContextUtils.getBean("StoreFacade");
   
    @RequestMapping(value =  RoleAction.LIST, method = RequestMethod.GET)
    @ApiOperation(value = "当前登陆用户可以管理的店铺", httpMethod = "GET", response = StoreVo.class)
    public void LIST(@ApiParam(value = "起始值") @RequestParam(value = "offset", defaultValue = "0") int offset,
                      @ApiParam(value = "每页大小") @RequestParam(value = "length", defaultValue = "10") int length,
                      @ApiParam(value = "关键词") @RequestParam (value = "keyword", required = false) String keyword,
                      @ApiParam(value = "排序字段") @RequestParam(value = "sort", required = false) String sort,
                      @ApiParam(value = "排序规则", allowableValues = "desc, asc") @RequestParam(value = "order", required = false) String order,
                      HttpServletResponse response, StoreVo storeVo) throws Exception {
        PagingResult result = storeFacade.queryEntity(storeVo, offset, length, keyword, sort);
        ResponseUtils.writeSuccessPagingResult(response, result);
   }
    //@RequiresAuthentication
    @RequestMapping(value = "selectStore/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "选择当前店铺", httpMethod = "GET")
    public void selectStore(@ApiParam(value = "店铺编号", required = true) @PathVariable(value = "id") Long[] id, HttpServletResponse response) throws Exception {
        storeFacade.delete(Store.class, id);
        ResponseUtils.writeSuccessResult(response);
    }
}
